package br.com.acs.CameraIP.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.acs.CameraIP.dao.PerfilDao;
import br.com.acs.CameraIP.dao.PerfilDaoImp;
import br.com.acs.CameraIP.model.Perfil;

@FacesConverter(forClass=Perfil.class, value="perfilConverter")
public class PerfilConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		
		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		try {
  		   if(arg2 != null){
			  PerfilDao dao = new PerfilDaoImp();
			  Perfil perfil = dao.getPerfil((Long) arg2);
		      return perfil.getDescricaoPerfil();
		  }
		  return null;
	   } catch (Exception e ){
		  return null;
       }
	}   
}
